package br.com.sebrae.pr.sebraemavenear;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import br.com.sebrae.pr.sgp.entities.World;
import br.com.sebrae.pr.sgp.services.HelloWorldServiceRemote;

@ManagedBean
@SessionScoped
public class TesteMB {

    @EJB
    private HelloWorldServiceRemote helloWorldService;

    private long i = 1;

    private World world;
    private String log = "OK!";

    public TesteMB() {

    }

    @PostConstruct
    public void carregarDadosInicializacao() {
        try {
            world = helloWorldService.findWorldById(i);
        } catch (Exception e) {
            log = "ERRO: " + e.toString();
        }
    }

    public void atualizar() {
        try {
            i++;
            world = helloWorldService.findWorldById(i);
            log = "OK!";
        } catch (Exception e) {
            log = "ERRO: " + e.toString();
        }
    }

    public World getWorld() {
        return world;
    }

    public void setWorld(World world) {
        this.world = world;
    }

    public String getLog() {
        return log;
    }

    public void setLog(String log) {
        this.log = log;
    }
}
